<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>线索列表</title>
    <jsp:include page="../../import.jsp" flush="true"/>
    <!-- 是否显示设置敞口按钮 -->
    <sys:funcAuth resCd="LinkCrAmt">
        <span id="isShowLinkCrAmtBtn"/>
    </sys:funcAuth>
</head>
<body class="iframeBody">
<div class="Wrapper">
    <div id="pageInTab" class="pageInTab">
        <div tabid="tabA" title="已拨打" lselected="true">
            <div class="searchArea">
                <form id="searchBar">
                    <div class="fieldset1 clearFix">
                        <%--<div class="fieldBox" id="searchPrjNmId">
                            <div class="label">编号</div>
                            <div class="field">
                                <input name="odrNo" id="odrNo" type="text" class="ui-textbox" value="">
                            </div>
                        </div>--%>
                        <div class="fieldBox" id="searchCstNmId" hidden="hidden">
                            <div class="label">是否拨打</div>
                            <div class="field">
                                <%--<input name="isFp" id="isFp" type="text" class="ui-textbox" value="0">--%>
                                <select name="isCall" id="isCall">
                                    <option value=" ">--请选择--</option>
                                    <option value="1" selected="selected">已拨打</option>
                                    <%--<c:forEach items="${odrStsCdList}" var="opt">
                                        <option value="${opt.key}">${opt.value}</option>
                                    </c:forEach>--%>
                                </select>
                            </div>
                        </div>
                        <div class="fieldBox" id="searchCstNmId">
                            <div class="label">所属区域</div>
                            <div class="field">
                                <%--<input name="isFp" id="isFp" type="text" class="ui-textbox" value="0">--%>
                                <!-- <input name="rgnProvCd" id="rgnProvCd" type="text" class="ui-textbox" value=""> -->
                                <jsp:include page="../../system/sysRegion/region.jsp" flush="true">
                                    <jsp:param name="regionShowLvl" value="2"/>
                                </jsp:include>
                            </div>
                        </div>
                        <div class="fieldBox" id="searchCstNmId">
                            <div class="label">是否接通</div>
                            <div class="field">
                                <%--<input name="isFp" id="isFp" type="text" class="ui-textbox" value="0">--%>
                                <select name="isConneced" id="isConneced">
                                    <option value=" ">--请选择--</option>
                                    <option value="0" >未接通</option>
                                    <option value="1" >已接通</option>
                                </select>
                            </div>
                        </div>
                            <div class="fieldBox" id="a">
                                <div class="label">是否kp</div>
                                <div class="field">
                                    <select name="isKp" id="isKp">
                                        <option value=" " >--请选择--</option>
                                        <option value="0" >否</option>
                                        <option value="1" >是</option>
                                    </select>
                                </div>
                            </div>
                            <div class="fieldBox" id="b">
                                <div class="label">客户意向</div>
                                <div class="field">
                                    <select name="intention" id="intention">
                                        <option value=" ">--请选择--</option>
                                        <option value="0" >没有意向</option>
                                        <option value="1">可深入沟通</option>
                                        <option value="2">高意向有车可做</option>
                                        <option value="3">已和狮桥合作</option>
                                        <option value="4">公司不做车相关业务</option>
                                    </select>
                                </div>
                            </div>
                        <div class="clearFix"></div>
                        <div class="btnsBox">
                            <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                            <span id="clearBtn" onclick="clearBtn();" class="sq-button sq-button-round">清空</span>
                            <!-- <span id="download" class="sq-button sq-button-round">导出</span> -->
<%--                            <span id="exportDetailBtn" class="sq-button sq-button-round">导出</span>--%>
                            <%--批量分配按钮--%>
                            <%--<span id="batchFpBtn" class="sq-button sq-button-round">批量分配</span>--%>
                        </div>
                    </div>
                </form>
            </div>

            <div id="ligergrid1" class="sq-grid"></div>
        </div>
    </div>
</div>


<div id="chooseFlowDIV" style="display:none">
    <div id="ligergrid_flowStart" class="sq-grid"></div>
</div>
<div id="ywchange_result" style="display:none">
    <form id="ywchange_result_form">
    </form>
</div>
<script src="../js/ligerDateEditor.js" type="text/javascript"></script>
<script type="text/javascript">

    $("#download").click(function () {
        var form = new liger.get("searchBar");
        var data = form.getData();
        $.ajax({
            type: "post",
            url: '<%=path%>/carloan/odrclueinfo/download.do?',
            data: {}

        });
    });
    $(function () {
        $("#endTime").ligerDateEditor();
        $("#beginTime").ligerDateEditor();
    })

    var isShowLinkCrAmtBtn = $("#isShowLinkCrAmtBtn");
    var isLnkCompFlag = '${isLnkCompFlag}';
    if (isShowLinkCrAmtBtn.length && isLnkCompFlag && isLnkCompFlag == 1) {
        $("#compCrLim").show();
        $("#compCrLimText").show();
    }

    var grid = null;
    var queryFlag = '${queryFlag}'; //只查询列表
    var updateFlag = '${updateFlag}';//业务移交
    var updateSunFlag = '${updateSunFlag}';//供应商及账号修改
    var splPrjViewFlag = '${splPrjViewFlag}';//供应商项目页面
    var mgrPrjViewFlag = '${mgrPrjViewFlag}';//客户经理关联项目页面
    var isLnkPrjViewFlag = '${isLnkPrjViewFlag}';//挂靠公司管理项目页面
    var pageInApp = {}; // to 下一级子窗口 接口
    var pageInTab = null;
    $(function () {
        initTab();
        g = manager = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/carloan/odrphonenoteweb/initList.do',
            method: 'get',
            columns: [
                {
                    display: '公司ID',
                    name: 'id',
                    id: ' ',
                    minWidth: 140,
                    align: 'center',
                    enabledSort: true,
                    hide: true,
                },
                {
                    display: '公司名称', name: 'compNm', align: 'center', minWidth: 140,
                    enabledSort: true
                },
                {display: '所属区域', name: 'prnCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '所属城市', name: 'cyCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '联系人姓名', name: 'odrChannelInfoDTO.channelNm', minWidth: 100, enabledSort: true},
                {display: '联系人电话', name: 'odrChannelInfoDTO.channelMp', minWidth: 100, enabledSort: true},
                {display: '是否kp', name: 'odrPhoneNoteWebDTO.isKpNm', minWidth: 100, enabledSort: true},
                {display: '拨打状况', name: 'odrPhoneNoteWebDTO.isConnectedNm', minWidth: 100, enabledSort: true},
                {display: '客户意向', name: 'odrPhoneNoteWebDTO.intentionNm', minWidth: 100, enabledSort: true},
                {display: '是否需要再次跟进', name: 'odrPhoneNoteWebDTO.isThreedayFollowinNm', minWidth: 100, enabledSort: true},

                /*{display: '联系人电话', name: 'id', minWidth: 140, align: 'center', enabledSort: true},
                {display: '所属市', name: 'rgnCyCd', minWidth: 140, align: 'center', enabledSort: true},
                {display: '客户经理', name: 'cstMgrNm', minWidth: 140, align: 'center', enabledSort: true},
                {display: '客户经理手机号', name: 'cstMgrMp', minWidth: 140, align: 'center', enabledSort: true},
                {display: '创建时间', name: 'crtTm', width: 100, enabledSort: true, render:renderDate},
                {display: '期望贷款金额(万元)', name: 'contAmtD', width: 100, enabledSort: true},*/
                /*{display: '估值内容', name: 'content', width: 100, enabledSort: true},*/
                /* { display: '省公司', name: 'prOrgCdNm', width: 100 , enabledSort:true},
                 { display: '分公司', name: 'cyOrgCdNm', width: 100 , enabledSort:true},
                 { display: '项目类型', name: 'prjTypCdNm', width: 150, enabledSort:true},
                 { display: '业务模式', name: 'bizTypCdNm', minWidth: 140 , enabledSort:true},
                 { display: '预约状态', name: 'odrStsCdNm', minWidth: 100 , enabledSort:true},
                  { display: '申请单号', name: 'pNo', minWidth: 140 ,
                       render: function (rowdata, rowindex, value, column) {
                         var h = '';
                         if(value&&value!="null"){
                             h+='<a href="javascript:commShowFlow(';
                             h+="'"+rowdata.pInstId+"',";
                             h+="'"+rowdata.flowAudStsCd+"',";
                             h+="'"+rowdata.id+"'";
                             h+=')">'+value+'</a>'
                         }
                         return h;
                     },
                     enabledSort:true},
                 { display: '数据来源', name: 'dateResCdNm', minWidth: 100 , enabledSort:true},
                 { display: '创建时间', name: 'crtTm', minWidth: 100 , render:renderDate, enabledSort:true},*/
                getOptColumn()
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -20,
            checkbox: true,
            delayLoad: true,
            rownumbers: true
        });
        //   initOrgTree();
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();
        $("#searchBtn").click(function (event) {
            var call = $("#isCall").val();
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            };
            grid.reload();
        });
        var form = new liger.get("searchBar");
        var data = form.getData();
        for (name in data) {
            grid.setParm(name, data[name]);
        }
        ;
        grid.reload();

        /* export excel : start */
        //导出详情
        $("#exportDetailBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            $.ajax({
                type: 'get',
                data: data,
                dataType: 'json',
                url: '<%=path%>/carloan/odrclueinfo/exportOdrClueInfoDetail.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    console.log(JSON.stringify(msg));
                    wait_dialog.close();
                    if (msg.success == 1) {
                        window.open(msg.data);
//                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
//                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
        /* export excel :end */
        /*批量分配*/
        $("#batchFpBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();

            var selecteds = g.getSelecteds();
            var usrId = '';
            for (var i = 0; i < selecteds.length; i++) {
                usrId += (selecteds[i].id) + "_";
            }

            $.ajax({
                type: 'POST',
                data: {
                    ids: usrId,
                    usrId: data.employ

                },
                dataType: 'json',
                url: '<%=path%>/carloan/odrcompinfo/distribute.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    console.log(JSON.stringify(msg));
                    wait_dialog.close();
                    if (msg.success == 1) {
                        //                 window.open(msg.data);
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
//                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
        /*批量分配*/
    });

    var loadedTabs = [];

    //初始化Tab页签
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                var selectedRows = grid.getSelectedRows();
            }
        });
        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    };

    //获取操作列
    function getOptColumn() {
        var column = {
            display: '详情',
            isSort: false,
            width: 150,
            align: 'center',
            render: function (rowdata, rowindex, value) {
                var h = "";
                h += '<a class="sq-button-hasicon" href="javascript:detailBtn(';
                h += "'" + rowdata.id + "'";
                h += ')"><i class="sqBtnIco_2"></i>详情</a>';
                //yaoxr
                /*var f = "";
                f += '<a class="sq-button-hasicon" href="javascript:detailUpdateBtn(';
                f += "'" + rowdata.clueId + "'";
                f += ')"><i class="sqBtnIco_2"></i>编辑</a>';*/
                return h;
            }
        }
        return column;

    }

    //显示流程
    function commShowFlow(_pInstId, _audStsCd, _businessKey) {
        if (StringUtils.isEmpty(_pInstId)) {
            UIUtils.alertWarning(CommonConstant.C_P_INSTANCEID_NOT_HERE);
            return;
        }
        var _formUrl = "/carloan/odrbscinfo/toAuditOdrInfoPage.do?isDetail=1" + "@@processInstanceId=" + _pInstId + "@@odrId=";
        var params = "?pInsId=" + _pInstId + "&status=" + _audStsCd + "&businessKey=" + _businessKey + "&formUrl=" + _formUrl;
        Add_navTab('tab_cst_invoice_flow_' + _businessKey, '查看流程', "<%=path%>/flow/flow/toFlowShowPageFowBus.do" + params);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    function addPhoneNote(id) {
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }

        Add_navTab('tab_phone_add' + id, '添加拜访记录', '<%=path%>/carloan/odrphonenoteweb/toAddPage.do?fromPrjFlag=' + fromPrjFlag + '&&id=' + id + '&&detailFlag=' + detailFlag);
    }

    function detailBtn(id) {
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }
        Add_navTab('tab_phone_detail' + id, '拜访记录详情', '<%=path%>/carloan/odrphonenoteweb/toDetailPage.do?fromPrjFlag=' + fromPrjFlag + '&&id=' + id + '&&detailFlag=' + detailFlag);
    }

    function detailUpdateBtn(id) {
        var fromPrjFlag = true;
        var detailFlag = true;

        var _flag = $("#fromPrjFlagId").val();//来自哪里
        if (StringUtils.isNotEmpty(_flag)) {
            if (_flag == 'false') {
                fromPrjFlag = false;
            }
        }

        Add_navTab('tab_odrclueinfoUpdate_detail' + id, '线索编辑', '<%=path%>/carloan/odrclueinfo/toUpdateDetailPage.do?fromPrjFlag=' + fromPrjFlag + '&&id=' + id + '&&detailFlag=' + detailFlag);
    }

    function clearBtn() {
        $("#searchBar").ligerForm();
        var form = new liger.get("searchBar");
        form.setData({
            usrId: " ",
            rgnProvCd: " ",
            rgnCityCd: " ",
            isConneced: " ",
            isKp: " ",
            intention: " ",
            isThreedayFollowIn: " ",
            beginTime: " ",
            endTime: " ",
        });
    }

    //发起流程 -yaoxr
    function addFlowStart(odrId) {
        if (!odrId) {
            $.ligerDialog.SQalert({content: "预约ID不能为空.", SQ_type: "warning"});
            return;
        }
        $.ligerDialog.confirm(FlowConstant.FLOW_ADD_START_CONFIRM, function (flag) {
            if (flag == false) {
                return;
            }
            ;
            var wait_dialog = $.ligerDialog.SQalert({
                content: LogUtils.LOG_CMM_DATA_LOADING,
                SQ_type: "waitting",
                onClose: function () {
                }
            });
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '<%=path%>/carloan/odrbscinfo/addFlowStart.do?odrId=' + odrId,
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {//成功发起流程
                        //UIUtils.alertSuccessHold1(msg.info);
                        var url = '<%=path%>/flow/flow/getFlowNextAssigne.do?key=' + msg.data;
                        FlowUtils.alertNextFlowAssign(url);
                        grid.reload();
                    } else if (msg.success == 0) {//错误
                        UIUtils.alertErrorHold1(msg.info);
                    }
                }
            });
        });
    }

</script>

</body>
</html>